import { NestFactory } from '@nestjs/core';
import { Logger } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

import { AppModule } from './app.module';
import Config from './config/config';

declare const module: any;

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('api/mock');

  const options = new DocumentBuilder()
    .setTitle('SNAKE-API')
    .setDescription('灵蛇出动 快速接口挡板工程之后端工程接口文档')
    .setVersion('1.0')
    .addBearerAuth()
    // 设置基础路径  与全局的前缀对应
    .setBasePath('api/mock')
    // 设置开发者联系邮箱
    .setContactEmail('656487723@qq.com')
    // 设置外部文档
    .setExternalDoc(
      '有道接口文档',
      'http://note.youdao.com/noteshare?id=16f2ca3f1b3ae33efb6d08e0a08ffeef'
    )
    .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('swagger', app, document);

  await app.listen(Config.port);
  Logger.log(`Server running on http://localhst:${Config.port}`, 'Bootstrap');

  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => app.close());
  }
}
bootstrap();
